package com.hyq.learn.api.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

/**
 * 服务静态配置，配置内容参考config/application*.yml文件
 */
@Validated
@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
public class ApplicationProperties {

    /**
     * HTTP CLIENT连接相关配置。
     */
    private final Http http = new Http();

    public Http getHttp() {
        return http;
    }

    /**
     * HTTP CLIENT连接相关配置信息实体。
     */
    public static class Http {
        public static final int DEFAULT_MAX_PER_ROUTE = 20;
        public static final int DEFAULT_TOTAL_CONNECTION = 200;

        public static final int DEFAULT_READ_TIMEOUT = 1000;
        public static final int DEFAULT_CONNECT_TIMEOUT = 1000;
        public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = 1000;

        private int maxPerRoute = DEFAULT_MAX_PER_ROUTE;
        private int maxTotal = DEFAULT_TOTAL_CONNECTION;

        private int readTimeout = DEFAULT_READ_TIMEOUT;
        private int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
        private int connectionRequestTimeout = DEFAULT_CONNECTION_REQUEST_TIMEOUT;

        public int getMaxPerRoute() {
            return maxPerRoute;
        }

        public void setMaxPerRoute(int maxPerRoute) {
            this.maxPerRoute = maxPerRoute;
        }

        public int getMaxTotal() {
            return maxTotal;
        }

        public void setMaxTotal(int maxTotal) {
            this.maxTotal = maxTotal;
        }

        public int getReadTimeout() {
            return readTimeout;
        }

        public void setReadTimeout(int readTimeout) {
            this.readTimeout = readTimeout;
        }

        public int getConnectTimeout() {
            return connectTimeout;
        }

        public void setConnectTimeout(int connectTimeout) {
            this.connectTimeout = connectTimeout;
        }

        public int getConnectionRequestTimeout() {
            return connectionRequestTimeout;
        }

        public void setConnectionRequestTimeout(int connectionRequestTimeout) {
            this.connectionRequestTimeout = connectionRequestTimeout;
        }
    }
}
